package com.sc.nft.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.dto.ExportRecordsDTO;
import com.sc.nft.entity.SysMember;
import com.sc.nft.entity.dto.ExternalLinkPageAdminDTO;
import com.sc.nft.entity.vo.AdminExternalLinkListVO;
import com.sc.nft.entity.vo.ExportRecordsVO;
import com.sc.nft.enums.ExportTypeEnum;
import com.sc.nft.enums.ExportTypeStatusEnum;
import com.sc.nft.pool.SysMemberPool;
import com.sc.nft.service.ExportRecordsService;
import com.sc.nft.service.SysMemberService;
import com.sc.nft.sup.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Objects;

/**
 * @author 朱梦晨
 * @Description: 导出记录
 * @date 2024-07-25
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/exportRecords")
@Api(tags = "导出记录")
public class ExportRecordsController {

    private final ExportRecordsService exportRecordsService;
    private final SysMemberService sysMemberService;

    @PostMapping(value = "/page", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "导出记录列表", notes = "导出记录列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<Page<AdminExternalLinkListVO>> exportRecordsListPage(@Validated @RequestBody ExportRecordsDTO exportRecordsDTO) {
        exportRecordsDTO.setCreatorId(SysMemberPool.getMember().getId());
        Page<ExportRecordsVO> exportRecordsVOPage = exportRecordsService.exportRecordsList(exportRecordsDTO);
        List<ExportRecordsVO> records = exportRecordsVOPage.getRecords();
        for (ExportRecordsVO record : records) {
            record.setExportTypeText(ExportTypeEnum.getName(record.getExportType()).getName());
            record.setStatusText(ExportTypeStatusEnum.getName(record.getStatus()).getName());
            SysMember sysMember= sysMemberService.getById(record.getCreatorId());
            if (Objects.nonNull(sysMember)){
                record.setCreatorName(sysMember.getUserName());
            }
        }
        return PageResult.success(exportRecordsVOPage);
    }






}
